package com.xjtu.repository;

import com.xjtu.model.Call;
import com.xjtu.model.Chat;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;


@Repository
public class CallRepository {

    @Resource
    private MongoTemplate mongoTemplate;


    public void save(Call call) {
        mongoTemplate.save(call);
    }


    public void deleteById(String from) {
        Query query = new Query();
        query.addCriteria(Criteria.where("from").is(from));
        mongoTemplate.remove(query, Chat.class);
    }


    public List<Chat> find(Query query) {
        List<Chat> calls = mongoTemplate.find(query, Chat.class);
        return calls;
    }


    public List<Chat> findAll() {
        return mongoTemplate.findAll(Chat.class);
    }

    public Page<Chat> findByPage(Pageable pageable, Query query) {
        return null;
    }
}
